<?php

/**
 * 
 * @author Youssef Driouach
 *
 */
class Application_Model_Object
{
	protected $_objectId;
	protected $_name;
	protected $_description;
	protected $_url;
	protected $_images;
	//TODO add images
	


	public function __construct(array $options = null)
	{
		if (is_array($options)) {
			$this->setOptions($options);
		}
	}
	
	public function __set($name, $value)
	{
		$method = 'set' . $name;
		if (('mapper' == $name) || !method_exists($this, $method)) {
			throw new Exception('Invalid object '.$name.' property');
		}
		$this->$method($value);
	}
	
	public function __get($name)
	{
		$method = 'get' . $name;
		if (('mapper' == $name) || !method_exists($this, $method)) {
			throw new Exception('Invalid object  '.$name.' property');
		}
		return $this->$method();
	}
	
	public function setOptions(array $options)
	{
		$methods = get_class_methods($this);
		foreach ($options as $key => $value) {
			$method = 'set' . ucfirst($key);
			if (in_array($method, $methods)) {
				$this->$method($value);
			}
		}
		return $this;
	}
	
	/**
	 * @return the $_objectId
	 */
	public function getObjectId() {
		return $this->_objectId;
	}
	
	/**
	 * @param field_type $_objectId
	 */
	public function setObjectId($_objectId) {
		$this->_objectId = $_objectId;
	}
	
	/**
	 * @return the $_name
	 */
	public function getName() {
		return $this->_name;
	}
	
	/**
	 * @return the $_description
	 */
	public function getDescription() {
		return $this->_description;
	}
	
	/**
	 * @return the $_url
	 */
	public function getUrl() {
		return $this->_url;
	}
	
	/**
	 * @param field_type $_name
	 */
	public function setName($_name) {
		$this->_name = $_name;
	}
	
	/**
	 * @param field_type $_description
	 */
	public function setDescription($_description) {
		$this->_description = $_description;
	}
	
	/**
	 * @param field_type $_url
	 */
	public function setUrl($_url) {
		$this->_url = $_url;
	}
	
	/**
	 * @return the $_images
	 */
	public function getImages() {
		return (array)$this->_images;
	}
	
	/**
	 * @param field_type $_images
	 */
	public function setImages(array $_images) {
		$this->_images = $_images;
	}
}